﻿<UserControl x:Class="CannedHeater.View.SettingsView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:Converters="clr-namespace:CannedHeater.View.Converters"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    d:DesignHeight="480" d:DesignWidth="480">

    <!-- DataContext set from SettingsPage -->
    
    <UserControl.Resources>
        <Converters:BooleanNegationConverter x:Key="booleanNegationConverter"/>
        <Converters:BoolValidIndicatorToBrushConverter x:Key="boolValidIndicatorToBrushConverter"/>
    </UserControl.Resources>
    
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition/>
        </Grid.RowDefinitions>

        <TextBlock Grid.Row="0" Text="Controller IP address" FontSize="30"/>
        <Grid Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>

            <TextBox Text="{Binding NETDUINO_DEVICE_IPTxt, Mode=TwoWay}"
                     IsEnabled="{Binding ElementName=IsAuto, Path=IsChecked, Converter={StaticResource booleanNegationConverter}}">
                <TextBox.InputScope>
                    <InputScope>
                        <InputScopeName NameValue="Digits"/>
                    </InputScope>
                </TextBox.InputScope>
            </TextBox>
            <CheckBox IsChecked="{Binding NETDUINO_DEVICE_IP_AUTO, Mode=TwoWay}"
                      x:Name="IsAuto" Grid.Column="1" Content="Auto"/>
        </Grid>

        <TextBlock Grid.Row="2" Text="Controller Port:" FontSize="30"/>
        <!-- Note the foreground binding to set red foreground color in case of invalid value
             Ideally NotifyOnValidationError=True, ValidatesOnExceptions=True should have been used,
             however exceptions are going 'unhandled' even with ValidatesOnExceptions=True.
             Might be a simple workaround, but using a converter this way is also simple, and works -->
        <TextBox Text="{Binding NETDUINO_DEVICE_PORTTxt, Mode=TwoWay}"
                 Foreground="{Binding NETDUINO_DEVICE_PORT_VALID, Converter={StaticResource boolValidIndicatorToBrushConverter}, ConverterParameter={StaticResource PhoneTextBoxForegroundBrush}}"
                 Grid.Row="3">
            <TextBox.InputScope>
                <InputScope>
                    <InputScopeName NameValue="Digits"/>
                </InputScope>
            </TextBox.InputScope>
        </TextBox>

        <TextBlock Grid.Row="4" Text="Pachube API Key:" FontSize="30"/>
        <TextBox Text="{Binding PACHUBE_API_KEYTxt, Mode=TwoWay}" Grid.Row="5"/>

        <TextBlock Grid.Row="6" Text="Pachube FEED ID:" FontSize="30"/>
        <!-- Note the foreground binding to set red foreground color in case of invalid value
             Ideally NotifyOnValidationError=True, ValidatesOnExceptions=True should have been used,
             however exceptions are going 'unhandled' even with ValidatesOnExceptions=True.
             Might be a simple workaround, but using a converter this way is also simple, and works -->
        <TextBox Text="{Binding PACHUBE_FEED_IDTxt, Mode=TwoWay}" Grid.Row="7"
                 Foreground="{Binding PACHUBE_FEED_ID_VALID, Converter={StaticResource boolValidIndicatorToBrushConverter}, ConverterParameter={StaticResource PhoneTextBoxForegroundBrush}}">
            <TextBox.InputScope>
                <InputScope>
                    <InputScopeName NameValue="Digits"/>
                </InputScope>
            </TextBox.InputScope>
        </TextBox>
    </Grid>
</UserControl>
